<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>WebRTC Video to Canvas</title>
</head>
<body>
<canvas id="videoCanvas" width="300" height="500"></canvas>
<script>
    async function startWebcam() {
        try {
            const constraints = { video: true, audio: false };
            const stream = await navigator.mediaDevices.getUserMedia(constraints);
            const videoElement = document.createElement('video');
            videoElement.srcObject = stream;
            // videoElement.style.transform = 'rotate(90deg)'
            await videoElement.play();

            const canvas = document.getElementById('videoCanvas');
            const context = canvas.getContext('2d');

            function drawVideo() {
                context.drawImage(videoElement, 0, 0, canvas.width, canvas.height);
                requestAnimationFrame(drawVideo);
            }
            drawVideo();
        } catch (error) {
            console.error('Error accessing the camera:', error);
        }
    }

    startWebcam();
</script>
</body>
</html>